Telegram Group & Telegram Channel
💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/proglib_academy/2787
Create:
Last Update:

💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст

BY Proglib.academy | IT-курсы




Share with your friend now:
tg-me.com/proglib_academy/2787

View MORE
Open in Telegram


Proglib academy | IT курсы Telegram | DID YOU KNOW?

Date: |

At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?

NEWS: Telegram supports Facetime video calls NOW!

Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another option—secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secure—like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.

Proglib academy | IT курсы from in


Telegram Proglib.academy | IT-курсы
FROM USA